package gui;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextArea;

import pl.CC;

public class ResultWindow extends JDialog{
	
	private CC cc;
	private JButton reset;
	private JTextArea area;
	private JLabel resultsLabel;
	
	public ResultWindow(CC c){
		super();
		setSize(495, 355);
		setTitle("Wyniki");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setResizable(false);
		setLayout(null);
		this.cc = c;
		init();
		fill();
		
	}
	
	private void fill(){
		double[] res = cc.showResults();
		area.setText("");
		for (int i=0;i<res.length-1;i++){
			area.append("x"+String.valueOf(i+1)+" = "+String.valueOf(res[i])+"\n");
		}
		area.append("Wartość funkcji celu: "+String.valueOf(res[res.length-1])+"\n");
	}
	
	private void init(){
		reset = new JButton("Nowe zadanie");
		add(reset);
		reset.setBounds(0, 290, 480, 30);
		reset.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				EventQueue.invokeLater(new Runnable() {
					public void run() {
						MainWindow window = new MainWindow();
						window.setVisible(true);
						dispose();
					}
				});
			}
		});
		
		area = new JTextArea();
		add(area);
		area.setBounds(0, 30, 480, 260);
		area.setEditable(false);
	}
}
